/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javamail.sip.util;


/**
 *
 * @author sriram
 */
public enum eSipRespCode {
    NIL(0, 0, ""),
    OK(1, 200, "OK"),
    TRYING(2, 100, "Trying"),
    RINGING(3, 180, "Ringing"),
    NOTFOUND(4, 404, "Not Found");
    
    private final int index;
    private final int code;
    private final String reason;
    
    eSipRespCode(int index, int code, String reason) {
        this.index = index;
        this.code = code;
        this.reason = reason;
    }
    
    public int toInt() {
        return index;
    }
 
    public int toCode() {
        return code;
    }

    @Override
    public String toString() {
        return reason;
    }

    public static eSipRespCode fromCode(String code) {
        try {
            int id = Integer.parseInt(code);
            for (eSipRespCode meth : eSipRespCode.values()) {
            if(meth.toCode()==id)
                return meth;
            }
        } catch(NumberFormatException e) { }
        return NIL;
    }
   
    public static eSipRespCode fromString(String methodName) {
        for (eSipRespCode meth : eSipRespCode.values()) {
            if(methodName.equals(meth.toString()))
                return meth;
        }
        return NIL;
    }
}
